<?php
require_once 'include/base.php';
require_once 'include/topwrap.php';
require_once 'include/global.func.php';
require_once 'include/pagination.php';
require_once 'inc/config.php';
require_once 'inc/classes/db.php';
$db = new db($gDb);
$q = htmlspecialchars( trim($_GET['q']) );
$cate 	= !empty($_GET['cate']) ? $_GET['cate'] : '0';
$taoapi = new TopWrap(false,true);
$page 	= !empty($_GET['page']) ? intval($_GET['page']) : 1;
if ($q) {
    $keywords = $q;
    $time = time();
    $sql = "INSERT INTO ".$gDb['prefix']."keywords (`keyword`, `clicked`, `created`,`updated`) values ('$q',1,$time,$time)";
    if( !$db->query($sql) ) {
        $sql = "UPDATE ".$gDb['prefix']."keywords SET `clicked`=`clicked`+1, `updated`=$time WHERE `keyword`='$q'";
        $db->query($sql);
    } 
	$items  = $taoapi->searchItems($cate, $q, $page, 20);
    $pagination = new Pagination($items['total_results']);
    $description = "$q的搜索结果,共有".$items['total_results']."条,当前的第".$page."页";
} else {
    $keywords = "淘宝商品搜索";
    $description = "淘宝商品搜索";
}

$cates  = $taoapi->getItemCats();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="<?php echo $keywords; ?>" />
<meta name="description" content="<?php echo $description; ?>" />
<title><?php echo !empty($q) ? $q.'_' : ''; ?>爱淘搜索</title>
<link type="text/css" rel="stylesheet" href="static/search.css" />
<link type="text/css" rel="stylesheet" href="static/pagination.css" />

</head>

<body>
<?php include('blocks/nav.php'); ?>
<div id="item-container" style="line-height:25px;">
    <div class='search-nav'><a href="itemsearch.php">搜索首页</a> <?php echo !empty($q) ? '->'.$q.' ( '.$items['total_results'].' ) ': ''; ?></div>
    <div class="container">
    <div id="left-container">
	<dl class='item-wrap'>
	<?php if($items['taobaoke_items']['taobaoke_item']):?>
	<?php foreach($items['taobaoke_items']['taobaoke_item'] as $item):?>
		<dd>
			<div style="padding:5px; border-bottom:1px dashed #F60;">
            <div class='item-img'><a class="preview" href="item-<?php echo $item['num_iid'] ?>" target="_blank"><img src="<?php echo print_img(array('img'=>$item['pic_url'],'tp'=>'_120x120')); ?>" alt="<?php echo $item['title']; ?>" border=0 /></a></div>
				<div class='item-txt'>
                    <p><a href="item-<?php echo $item['num_iid']; ?>" target="_blank"><?php echo $item['title'];?></a></p>
					<p>¥:<?php echo $item['price'];?>元 &nbsp; &nbsp;<span>最近出售<?php echo $item['volume'];?>件</span></p>
					<p>商家:<a href="<?php echo $item['shop_click_url'];?>" target="_blank"><?php echo $item['nick'];?></a> 商家信用:<?php echo level(array('l'=>$item['seller_credit_score']));?></p>
					<p>商品所在地:<?php echo $item['item_location']; ?></p>
				</div>
				<div style="clear:both;"></div>
			</div>
		</dd>
	<?php endforeach;?>
	<?php else:?>
		<dd>输入关键字搜索产品</dd>
	<?php endif;?>
	</dl>
    <div style="clear:both;"><?php if( isset($pagination) )echo $pagination->getPagination();?></div>
    </div>    
    <div id="right-container">
<script language="javascript" type="text/JavaScript"> 
var alimama_pid= "mm_15052303_0_0"; 
var alimama_uniteid= "16767602"; 
var alimama_type= "1000"; 
var alimama_mode= "42"; 
var alimama_titlecolor= "0000FF"; 
var alimama_bgcolor="FFFFFF"; 
var alimama_bordercolor="E6E6E6"; 
var alimama_shopcat="1056"; 
</script> 
<script language="javascript" src="http://a.alimama.cn/sinf.js"></script>
    
    </div>
    </div>
</div>
<?php include('blocks/footer.php'); ?>
</body>
</html>
